﻿//将选择的用户设置域同步过滤
function openAddWin()
{
    var strUrl = "/_controls/lookup/map_selectUserMulti.aspx";
    var strReturn = openMyDlg("查找记录", strUrl, "gridxml=map_selectCompany.xml&rowslimit=5", "", 800, 600);

    if (strReturn.items.length == 0) return;
    var strUserGuid = "";

    for (var i = 0; i < strReturn.items.length; i++)
    {
        if (i == 0)
        {
            strUserGuid = strReturn.items[i].id;
        }
        else
        {
            strUserGuid += ";" + strReturn.items[i].id;
        }
    }

    if (strUserGuid.length == 0) return;

    //调用保存
    strUrl = "/Security/Security_XmlHTTP.aspx";
    strReturn = XmlHttpRequest(strUrl, "SaveUserSyncFilter", "userguid=" + escape(strUserGuid));

    var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
    xmlDom.loadXML(strReturn);

    try
    {
        var strResult = xmlDom.documentElement.attributes.getNamedItem("result").value;
        if (strResult != "true")	// 如果保存失败
        {
            var strError = xmlDom.documentElement.attributes.getNamedItem("errormessage").value;
            alert(strError);
            return;
        }
        else
        {
            appGrid.frameElement.Query();
        }
    }
    catch (e)
    {
        alert("将选择的用户设置域同步过滤失败！");
    }
}

function deleteUser()
{
    // 选中行对象数组
    var arrTr = appGrid.frameElement.getSelected();
    if (!arrTr) return;

    // 拼写 oids
    var strUserGuid = "";
    for (var i = 0; i < arrTr.length; i++)
    {
        if (i == 0)
        {
            strUserGuid += arrTr[i].oid;
        }
        else
        {
            strUserGuid += ";" + arrTr[i].oid;
        }
    }
    if (strUserGuid.length  == 0) return; 	// 如果没有选中记录
    if (!window.confirm("确定要删除选择的同步过滤用户吗？")) return;

    //调用删除
    var strFile = "/Security/Security_XmlHTTP.aspx";
    var strRtn = XmlHttpRequest(strFile, "DelUserSyncFilter", "userguid=" + escape(strUserGuid));

    var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
    xmlDom.loadXML(strRtn);

    try
    {
        var strResult = xmlDom.documentElement.attributes.getNamedItem("result").value;
        if (strResult != "true")	// 如果删除失败
        {
            var strError = xmlDom.documentElement.attributes.getNamedItem("errormessage").value;
            alert(strError);
            return;
        }
        else	// 如果删除失败
        {
            appGrid.frameElement.Query();
        }
    }
    catch (e)
    {
        alert("删除选择的同步过滤用户失败！");
    }
}